/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*   File:      MyDatabase_Parameters.cpp
*   Author:    刘洋兵
*   Function:  重新设置数据库参数界面
*   Time:      2025-09-09
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "MyDatabase_Parameters.h"
#include "ui_MyDatabase_Parameters.h"

/**
 * @brief  构造函数
 * @param  parent 父窗口
 */
MyDatabase_Parameters::MyDatabase_Parameters(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MyDatabase_Parameters)
{
    ui->setupUi(this);
}

/**
 * @brief  析构函数
 */
MyDatabase_Parameters::~MyDatabase_Parameters()
{
    delete ui;
}

/**
 * @brief  设置界面控件的初始化数据
 * @param  dataMap 设置的数据
 */
void MyDatabase_Parameters::setData(QMap<QString, QVariant>& dataMap)
{
    if (ui->comboBox_ip->findText(dataMap["ip"].toString())==-1) {
        ui->comboBox_ip->addItem(dataMap["ip"].toString());
    }
    if (ui->comboBox_port->findText(dataMap["port"].toString())==-1) {
        ui->comboBox_port->addItem(dataMap["port"].toString());
    }
    if (ui->comboBox_db->findText(dataMap["db"].toString())==-1) {
        ui->comboBox_db->addItem(dataMap["db"].toString());
    }
    if (ui->comboBox_username->findText(dataMap["username"].toString())==-1) {
        ui->comboBox_username->addItem(dataMap["username"].toString());
    }
    if (ui->comboBox_password->findText(dataMap["password"].toString())==-1) {
        ui->comboBox_password->addItem(dataMap["password"].toString());
    }
}

/**
* @brief  返回修改的数据库参数
*/
void MyDatabase_Parameters::on_pushButton_clicked()
{
    infomap["ip"] = ui->comboBox_ip->currentText();
    infomap["port"] = ui->comboBox_port->currentText().toInt();
    infomap["db"] = ui->comboBox_db->currentText();
    infomap["username"] = ui->comboBox_username->currentText();
    infomap["password"] = ui->comboBox_password->currentText();
    MyDatabase::getInstance().AlterDatabase(infomap);
    close();
}
